using System;
using System.Windows;
using System.Windows.Interactivity;
using System.Windows.Markup;
namespace Microsoft.Expression.Interactivity.Core
{
	[ContentProperty("Condition")]
	public class ConditionBehavior : Behavior<TriggerBase>
	{
		public static readonly DependencyProperty ConditionProperty = DependencyProperty.Register("Condition", typeof(ICondition), typeof(ConditionBehavior), new PropertyMetadata(null));
		public ICondition Condition
		{
			get
			{
				return (ICondition)base.GetValue(ConditionBehavior.ConditionProperty);
			}
			set
			{
				base.SetValue(ConditionBehavior.ConditionProperty, value);
			}
		}
		protected override void OnAttached()
		{
			base.OnAttached();
			base.AssociatedObject.PreviewInvoke += new EventHandler<PreviewInvokeEventArgs>(this.OnPreviewInvoke);
		}
		protected override void OnDetaching()
		{
			base.AssociatedObject.PreviewInvoke -= new EventHandler<PreviewInvokeEventArgs>(this.OnPreviewInvoke);
			base.OnDetaching();
		}
		private void OnPreviewInvoke(object sender, PreviewInvokeEventArgs e)
		{
			if (this.Condition != null)
			{
				e.Cancelling = !this.Condition.Evaluate();
			}
		}
	}
}
